package cn.bandeqing.pay.gnete.upbc.bean;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;


import com.gnete.upbc.comn.card.rpc.dto.CardMsgReqDTO;
import com.gnete.upbc.comn.card.rpc.dto.bean.FqInf;
import com.gnete.upbc.comn.card.rpc.dto.bean.RskInf;
import com.gnete.upbc.comn.card.rpc.dto.bean.TrxTrmInf;
import com.gnete.upbc.comn.code.rpc.dto.CodeMsgReqDTO;
import com.gnete.upbc.comn.code.rpc.dto.bean.BuyerInf;
import com.gnete.upbc.comn.code.rpc.dto.bean.GoodsDtl;
import com.gnete.upbc.comn.code.rpc.dto.bean.SceneInf;
import com.gnete.upbc.comn.rpc.dto.PaymentReqDTO;
import com.gnete.upbc.comn.rpc.dto.bean.PayMsgReqBody;
import com.gnete.upbc.comn.sign.rpc.dto.SignMsgReqDTO;
import com.gnete.upbc.comn.verify.rpc.dto.VerifyMsgReqDTO;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.RandomStringUtils;

public class BeanMock {
    public static String busiMerno = "898440160510003";

    public static String getMerOrdrNo(String busiMerno) {
        return busiMerno + new SimpleDateFormat("yyyyMMddHH").format(new Date()) + RandomStringUtils.randomNumeric(7);
    }

    public static String getMerOrdrNo() {
        return busiMerno + new SimpleDateFormat("yyyyMMddHH").format(new Date()) + RandomStringUtils.randomNumeric(7);
    }

    public static String getSubmitTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        return dateFormat.format(new Date());
    }

    public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();

    /**
     * 将对象转换为json字符串 ，用于日志输出
     */
    public static String toJson(Object value) {
        if (value == null) {
            return null;
        }
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); // 默认空字段不生成json节点
        return gson.toJson(value);
    }

    public static <T extends PayMsgReqBody> PaymentReqDTO<T> getPaymentReqDTO() {
        PaymentReqDTO<T> req = new PaymentReqDTO<T>();
        req.setBusiMerNo(busiMerno);
        req.setSndDt(getSubmitTime());
        req.setRemark("商户联调测试");
        req.setNotifyUrl("https://bdqapi.bmbanjia.cn/bdq-wechat-miniapp-api/payResult/orderDeposit");
        return req;
    }

    public static CodeMsgReqDTO getCodePayReqDTO() {
        CodeMsgReqDTO msgBody = new CodeMsgReqDTO();

        msgBody.setMerOrdrNo(getMerOrdrNo());
        msgBody.setTrxTtlAmt("1"); // 单位分
        msgBody.setTrxCurr("CNY");
        msgBody.setBusiId("00250005");
        msgBody.setBizFunc("111011");
        msgBody.setSubject("条码支付");
        msgBody.setOrdrDesc("支付");

        msgBody.setOprId("");
        msgBody.setTimeoutExpress("5m"); // 5分钟有效
        msgBody.setTrxType("NATIVE"); //扫码支付（支付宝）

        msgBody.setBuyerInf(BeanMock.getBuyerInfo());
        msgBody.setSceneInf(BeanMock.getSceneInfo());
        msgBody.setGoodsDtl(Arrays.asList(BeanMock.getGoodsDtl()));
//		msgBody.setFqInf(getFqInf());
        msgBody.setTrxTrmInf(BeanMock.getTrxTrmInf());
        msgBody.setRskInf(BeanMock.getRskInf());

//		msgBody.setNeedRcpt("true");
//		msgBody.setUndiscAmt("1");
//		msgBody.setDisvTag("1");
//		msgBody.setDiscAmt("1");
//		msgBody.setLimitPay("1");

        msgBody.setRemark("remark");
        msgBody.setRemark1("remark1");
        msgBody.setRemark2("remark2");
        msgBody.setRemark3("remark3");
        msgBody.setRemark4("");

        return msgBody;
    }


    public static CardMsgReqDTO getCardPayReqDTO() {
        CardMsgReqDTO msgBody = new CardMsgReqDTO();

        msgBody.setMerOrdrNo(getMerOrdrNo());
        msgBody.setTrxTtlAmt("100"); // 单位分
        msgBody.setTrxCurr("CNY");
        msgBody.setBusiId("10001");
        msgBody.setBizFunc("111011");
        msgBody.setBizType("10600");
        msgBody.setAuthCode("");
        msgBody.setSubMerOrdrNo(""); // 非复合交易请勿填写

        msgBody.getPyerInf().setPyerAcctIssrId("");
        msgBody.getPyerInf().setPyerBankCode("102");
        msgBody.getPyerInf().setPyerBankType("0102");
        msgBody.getPyerInf().setPyerBankName("中国工商银行");

        msgBody.getPyerInf().setPyerAcctType("0");   // 个人借记卡
        msgBody.getPyerInf().setPyerAcctNo("6228480246125491166"); // 6228480246125491166
        msgBody.getPyerInf().setPyerAcctName("曹朵一");
        msgBody.getPyerInf().setPyerIdType("0"); // 身份证
        msgBody.getPyerInf().setPyerIdNo("140123198109239750");
        msgBody.getPyerInf().setPyerMobile("13811784067");

        msgBody.getPyerInf().setPyerPrvAddrName("广东");
        msgBody.getPyerInf().setPyerCityAddrName("广州");
//		msgBody.getPyerInf().setPyerElectNo("100001");
        // 设备信息
        msgBody.setTrxTrmInf(getTrxTrmInf());
        msgBody.setRskInf(getRskInf());
        msgBody.setSceneInf(BeanMock.getSceneInfo());
        // msgBody.setFqInf(getFqInf());

        msgBody.setAbs("摘要");
        msgBody.setPs("附言");
        msgBody.setFundUse("用途");
        msgBody.setPltfrmNm("分期平台");
        msgBody.setRemark("订单详情Remark");
        msgBody.setRemark1("remark1");
        msgBody.setRemark2("remark2");
        msgBody.setRemark3("remark3");
        msgBody.setRemark4("");
        msgBody.setOrdrDesc("订单详情OrdrDesc");

        return msgBody;
    }

    public static SignMsgReqDTO getSignApplyReqDTO() {
        SignMsgReqDTO msgBody = new SignMsgReqDTO();

        msgBody.setMerOrdrNo(getMerOrdrNo());
        msgBody.getPyerInf().setPyerAcctIssrId("");
        msgBody.getPyerInf().setPyerBankCode("");
        msgBody.getPyerInf().setPyerBankType("");
        msgBody.getPyerInf().setPyerBankName("");
        msgBody.getPyerInf().setPyerAcctType("0"); // 身份证
        msgBody.getPyerInf().setPyerAcctNo("6228480246125490000"); // 6228480246125491166
        msgBody.getPyerInf().setPyerAcctName("曹朵一");
        msgBody.getPyerInf().setPyerIdType("0"); // 个人借记卡
        msgBody.getPyerInf().setPyerIdNo("140123198109239750");
        msgBody.getPyerInf().setPyerMobile("13811784067");

        msgBody.getPyerInf().setPyerLglRepNm("法人1");
        msgBody.getPyerInf().setPyerLglRepIdTp("0"); // 身份证
        msgBody.getPyerInf().setPyerLglRepIdNo("140123198109239750");
        msgBody.getSignInf().setSignMode("0"); //线上签约
        msgBody.getSignInf().setBizType("10501");
        msgBody.getSignInf().setDisableDate("20200924");
        msgBody.getSignInf().setSingleLimit("10000");
        msgBody.getSignInf().setLimitPeriodUnit("01");
        msgBody.getSignInf().setMaxCntLimit("999");

        msgBody.setRemark("remark");
        msgBody.setRemark1("remark1");
        msgBody.setRemark2("remark2");
        msgBody.setRemark3("remark3");
        msgBody.setRemark4("");
        return msgBody;
    }


    public static VerifyMsgReqDTO getVerifyApplyReqDTO() {
        VerifyMsgReqDTO msgBody = new VerifyMsgReqDTO();
        msgBody.setMerOrdrNo(getMerOrdrNo());
        msgBody.setBusiId("verify");

        msgBody.getVerifyInf().setAcctNo("6228480246125491166");
        msgBody.getVerifyInf().setName("曹朵一");
        msgBody.getVerifyInf().setCertNo("140123198109239750");
        msgBody.getVerifyInf().setMobile("13811784067");
        msgBody.getVerifyInf().setCertType("0");
        msgBody.getVerifyInf().setBankCode("102");

        msgBody.setRemark("remark");
        msgBody.setRemark1("remark1");
        msgBody.setRemark2("remark2");
        msgBody.setRemark3("remark3");
        msgBody.setRemark4("");

        msgBody.setTrxTrmInf(getTrxTrmInf());
        msgBody.setRskInf(getRskInf());
        return msgBody;
    }

    /**
     * 设备信息
     *
     * @return
     */
    public static TrxTrmInf getTrxTrmInf() {
        TrxTrmInf inf = new TrxTrmInf();
        inf.setTrxTrmType("00");
        inf.setTrxTrmNo("");
        inf.setTrxTrmIp("10.10.0.1");
        inf.setTrxTrmMac("F0E1D2C3B4A5");
        inf.setTrxTrmIccid("10001");
        inf.setTrxTrmImei("10002");
        inf.setTrxTrmImsi("10003");
        inf.setTrxTrmWifiMac("10004");
        inf.setTrxTrmSceneType("AND_SDK");
        inf.setTrxTrmMerAppName("全民付");
        inf.setTrxTrmMerAppId("com.tencent.tmgp.sgame");
        return inf;
    }

    /**
     * 风控监控信息
     *
     * @return
     */
    public static RskInf getRskInf() {
        RskInf inf = new RskInf();

        inf.setDevId("10000");
        inf.setDevcMode("设备型号XXX");
        inf.setDevcLanguage("JAV");
        inf.setDevcLocation("116.360207");
        inf.setDevcNumber("10086");
        inf.setDevcSimNumber("2");
        return inf;
    }

    public static BuyerInf getBuyerInfo() {
        BuyerInf buyerInfo = new BuyerInf();
        buyerInfo.setBankCode("00080808");
        buyerInfo.setAcctType("0");
// 		buyerInfo.setBuyerLgnId("酷酷基0920");
// 		buyerInfo.setBuyerUid("15088087976");
//		buyerInfo.setOpenId("10003");
//		buyerInfo.setSubOpenId("10004");
// 		buyerInfo.setName("name");
//		buyerInfo.setMobile("13820000000");
//		buyerInfo.setCertType("0");
// 		buyerInfo.setCertNo("440000000000000000");
//		buyerInfo.setMinAge("18");
//		buyerInfo.setFixBuyer("F");
//		buyerInfo.setNeedChkInfo("F");
        buyerInfo.setLimitCreditPay("0");

        return buyerInfo;
    }

    public static SceneInf getSceneInfo() {
        SceneInf sceneInfo = new SceneInf();
//		sceneInfo.setSellerUid("10005");
        sceneInfo.setStoreId("10006");
        sceneInfo.setStoreNm("一间小店");
        sceneInfo.setAreaCode("5810");
        sceneInfo.setAddress("广州");
        return sceneInfo;
    }

    public static GoodsDtl getGoodsDtl() {
        GoodsDtl goodsDtl = new GoodsDtl();
        goodsDtl.setGdsId("1001");
        goodsDtl.setGdsPlfId("10009");
        goodsDtl.setGdsNm("一件商品");
        goodsDtl.setGdsCnt("1");
        goodsDtl.setGdsPrice("1000");
        goodsDtl.setGdsCstPrice("1000");
        goodsDtl.setGdsCtgy("10010");
        goodsDtl.setGdsDesc("商品描述");
        goodsDtl.setShowUrl("127.0.0.1");
        return goodsDtl;
    }

    public static FqInf getFqInf() {
        FqInf fqInf = new FqInf();
        fqInf.setFqNum("02");
        fqInf.setFqRate("004500");
        fqInf.setFqStyle("0");
        return fqInf;
    }
}
